package com.fishery.customization.service.impl;

import com.fishery.customization.dao.ThemeDao;
import com.fishery.customization.dao.UserThemeDao;
import com.fishery.customization.entity.Theme;
import com.fishery.customization.entity.UserTheme;
import com.fishery.customization.service.UserThemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class UserThemeServiceImpl implements UserThemeService {

	@Autowired
	private UserThemeDao userThemeDao;

	@Autowired
	private ThemeDao themeDao;

	@Override
	public Theme getThemeOfUserByUserId(String userId) {
		String themeId = userThemeDao.findThemeIdOfUserByUserId(userId);
		return StringUtils.isEmpty(themeId) ? null : themeDao.findById(themeId);
	}

	@Override
	public boolean saveOrUpdateThemeOfUser(UserTheme userTheme) {
		return userThemeDao.upsertThemeOfUser(userTheme.getUserId(), userTheme.getThemeId()) > 0;
	}
}
